<meta charset="UTF-8">
<?php
require 'db_conn.php';
$db->query('set names utf8');
$id=isset($_GET['bid'])?$_GET['bid']:0;
if(empty($_POST)){   //修改留言
$sqlsel="select * from t_message where id='$id'";
$selrs=$db->query($sqlsel);  //结果集，不能直接读取
$row=$selrs->fetch_assoc();
//var_dump($row);
require 'edit_html.php';
}
else{
    //更新数据
$username=$_POST['username'];
$sex=$_POST['sex'];
$message=$_POST['message'];
$imgurl=$_POST['imgurl'];
$sqlupdate="update  t_message set username='$username',sex='$sex',message='$message',imgurl='$imgurl' where id='$id'";

$aaa=$db->query($sqlupdate);
if($aaa){
    echo "<script language='javascript' type='text/javascript'>";
    echo "alert('留言成功！');";
    echo "window.location.href='index.php';";
    echo "</script>";
}else{
     echo '留言不成功！';
}
}